<?php
/*
*
*
*     Author: Alex Scott
*      Email: alex@cgi-central.net
*        Web: http://www.cgi-central.net
*    Details: Admin Access log
*    FileName $RCSfile$
*    Release: 4.2.0 ($Revision: 4649 $)
*
* Please direct bug reports,suggestions or feedback to the cgi-central forums.
* http://www.cgi-central.net/forum/
*
* aMember PRO is a commercial software. Any distribution is strictly prohibited.
*
*/

require_once(APPLICATION_PATH . '/default/controllers/AdminUsersController.php');

class Am_Helpdesk_Grid_UserTab extends Am_Helpdesk_Grid {
    protected $user_id;
    public function __construct(Am_Request $request, Am_View $view) {
        parent::__construct($request, $view);
        $this->user_id = $this->getCompleteRequest()->get('user_id', 0);
        if ($this->user_id) {
            $this->getDataSource()->getDataSourceQuery()->addWhere('t.user_id=?d', $this->user_id);
        }
    }
}


class Helpdesk_AdminUserController extends Am_Controller_Pages 
{
    protected $layout = 'admin/user-layout.phtml';

    public function checkAdminPermissions(Admin $admin) {
        return $admin->hasPermission('helpdesk');
    }

    function preDispatch() {

        $this->getDi()->navigationUserTabs->setActive('helpdesk');

        $this->getDi()->helpdeskStrategy->setUserId(
                $this->getRequest()->getParam('user_id', 0)
        );

        $this->view->headLink()->appendStylesheet($this->view->_scriptCss('helpdesk-admin.css'));
        $this->setActiveMenu('users-browse');
        parent::preDispatch();
    }

    public function initPages() {
        $this->addPage('Am_Helpdesk_Grid_UserTab', 'index', 'Tickets')
                ->addPage(array($this, 'createController'), 'view', 'Conversation');
    }

    public function renderTabs() {
        return '';
    }

    public function createController($id, $title, $grid) {
        return new Am_Helpdesk_Controller($grid->getRequest(), $grid->getResponse(), $this->_invokeArgs);
    }
}